package com.coin900.coin.base.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-12-19
 * Time: 上午11:52
 * To change this template use File | Settings | File Templates.
 */
public class ValidatorUtil {
    /**
     * 验证邮箱格式
     */
    public static boolean isEmail(String strEmail) {
        String strPattern = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
        Pattern p = Pattern.compile(strPattern);
        Matcher m = p.matcher(strEmail);
        if (m.matches()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 手机号码
     * 移动：134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
     * 联通：130,131,132,145,152,155,156,1709,171,176,185,186
     * 电信：133,134,153,1700,177,180,181,189
     */
    //"^1(3[0-9]|4[57]|5[0-35-9]|7[01678]|8[0-9])\\d{8}$";
    /**
     * 中国移动：China Mobile
     * 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
     */
    //"^1(3[4-9]|4[7]|5[0-27-9]|7[0]|7[8]|8[2-478])\\d{8}$";
    /**
     * 中国联通：China Unicom
     * 130,131,132,145,152,155,156,1709,171,176,185,186
     */
     //"^1(3[0-2]|4[5]|5[56]|709|7[1]|7[6]|8[56])\\d{8}$";
    /**
     * 中国电信：China Telecom
     * 133,134,153,1700,177,180,181,189
     */
     //"^1(3[34]|53|77|700|8[019])\\d{8}$";

    /**
     *  验证手机号  验证成功返回true
     * @param mobile
     * @return
     */
    public static boolean checkMobile(String mobile) {
        String regex = "^1(3[0-9]|4[57]|5[0-35-9]|7[01678]|8[0-9])\\d{8}$";
        return Pattern.matches(regex,mobile);
    }

    /**
     * 校验用户名。3-6位文字、字母或数字
     * @param username
     * @return
     */
    public static boolean checkUsername(String username){
        String regex = "^(a-zA-Z0-9\\\\u4e00-\\\\u9fa5){3,6}";
        return Pattern.matches(regex,username);
    }
}
